/**
 * @file task_mmgr.c
 * @brief 
 * @author  ()
 * @version 1.0
 * @date 2024-09-13
 * 
 * @copyright Copyright (C) 2019 Queclink Wireless Solutions (ShenZhen) Co., Ltd. All Rights Reserved.
 * 
 * @par 修改日志:
 * <table>
 * <tr><th>Date       <th>Version <th>Author  <th>Description
 * <tr><td>2024-09-13 <td>1.0     <td>     <td>内容
 * </table>
 */
#include "global.h"
#include "bsp.h"
#include "bsp_modem.h"

#define LOG_TAG TAG_MMGR
#include "include/mmgr_log.h"
#include "include/mmgr_modem.h"
#include "include/mmgr_misc.h"
#include "cmsis_os2.h"
#include "modem/qlmodem/task_modem.h"
#include "bsp_modem.h"

static TaskHandle_t mmgr_handle;

/// @brief mmgr初始化
/// @param  
void task_mmgr_init(void)
{
    /* 1.杂项参数初始化 */
    mmgr_misc_init();

    /* 2.modem功能初始化 */
    mmgr_modem_init();
}

/// @brief mmgr处理流程
/// @param  
void task_mmgr_process(void)
{  
    /* 根据当前 DQA 模式, 确认执行函数 */
    if (tbox_dqa_mode_get()) {
        dqa_process();
    } else {
        application_process();
    }
}

/// @brief mmgr 处理线程
/// @param  
void task_mmgr_entry(void *param)
{
    task_mmgr_init();

    while(1)
    {
        task_mmgr_process();
        osDelay(100);
    }
}

/// @brief Mmgr功能入口函数
/// @param  
/// @return 
int32_t qltask_mmgr_start(void)
{
    /* 1. modem硬件初始化 */
    bsp_modem_init();

    /* 2. Create mmgr Thread with routine function mmgr_routine; */
    if(pdPASS != xTaskCreate(task_mmgr_entry, "mmgr", TASKSTACK_MMGR, NULL, TASKPRI_MMGR, &mmgr_handle))
    {
        Error_Handler();
    }

    return 0; 
}

